function mb_oct

deltheta = 45*pi/180;

t = linspace(0,10); 
[x,I,m] = lsode(@dot,[pi/2+deltheta 0]',t);

for i=1:length(t)
    draw(x(i,:));    
    pause(0.1);
end

function op = dot(x,t)

g = -9.81;
l = 1;
q = x(1,1);
qdot = x(2,1);

udot = -(g*cos(q))/(2*l*(sin(q) + 1));

op = [qdot;udot];

function draw(x)

theta = x(1,1);
theta1 = theta + pi/2;
theta2 = theta1 + pi;

atheta = (theta1+theta2)/2;
btheta = atheta + pi;
center = [cos(theta)-1 1]';

A = center + [cos(atheta) sin(atheta)]';
B = center + [cos(btheta) sin(btheta)]';

hold off
arc(center,1,theta1,theta2,'b');
hold on
line([A(1) B(1)],[A(2) B(2)],'LineWidth',2);
plot(B(1),B(2),'LineWidth',4);
axis([-2.5 0.5 0 2.5]);


function arc(center, radius,theta1,theta2, string)

theta = linspace(theta1,theta2);
x = center(1) + radius*cos(theta);
y = center(2) + radius*sin(theta);

plot(x,y,string,'LineWidth',2);
